//    uniCenta oPOS - touch friendly EPoS
//    Copyright (c) 2009 uniCenta
//    http://www.unicenta.net
//
//    This file is part of uniCenta oPOS
//
//    uniCenta oPOS is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    uniCenta oPOS is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with uniCenta oPOS.  If not, see <http://www.gnu.org/licenses/>.

//*** NOT USABLE FOR DERBY DB'S ***//

report = new com.openbravo.pos.reports.PanelReportBean();

report.setTitleKey("Menu.Top10Sales");
report.setReport("/com/openbravo/reports/top10sales");
report.setResourceBundle("com/openbravo/reports/top10sales_messages");

report.setSentence(
            "SELECT " +
			"PRODUCTS.REFERENCE, " +
			"PRODUCTS.NAME, " +
			"SUM(TICKETLINES.UNITS) AS UNITS, " +
			"SUM(TICKETLINES.UNITS * TICKETLINES.PRICE) + SUM(TICKETLINES.PRICE * TICKETLINES.UNITS * TAXES.RATE) AS GROSSTOTAL " +
			"FROM TICKETLINES " +
			"LEFT OUTER JOIN PRODUCTS ON TICKETLINES.PRODUCT = PRODUCTS.ID " +
			"LEFT OUTER JOIN TICKETS ON TICKETS.ID = TICKETLINES.TICKET " +
			"LEFT OUTER JOIN RECEIPTS ON RECEIPTS.ID = TICKETS.ID, TAXES " +
			"WHERE RECEIPTS.ID = TICKETS.ID AND TICKETS.ID = TICKETLINES.TICKET AND TICKETLINES.PRODUCT = PRODUCTS.ID AND ?(QBF_FILTER) " +
			"GROUP BY PRODUCTS.REFERENCE, PRODUCTS.NAME " +
			"ORDER BY GROSSTOTAL DESC " +
			"LIMIT 0, 10");
			
report.addParameter("RECEIPTS.DATENEW");
report.addParameter("RECEIPTS.DATENEW");
report.addQBFFilter(new com.openbravo.pos.reports.JParamsDatesInterval());
report.addParameter("PRODUCTS.NAME");
report.addParameter("PRODUCTS.PRICEBUY");
report.addParameter("PRODUCTS.PRICESELL");
report.addParameter("PRODUCTS.CATEGORY");
report.addParameter("PRODUCTS.CODE");
report.addQBFFilter(new com.openbravo.pos.ticket.ProductFilter());

report.addField("REFERENCE", com.openbravo.data.loader.Datas.STRING);
report.addField("NAME", com.openbravo.data.loader.Datas.STRING);
report.addField("UNITS", com.openbravo.data.loader.Datas.DOUBLE);
report.addField("GROSSTOTAL", com.openbravo.data.loader.Datas.DOUBLE);

report;

